package com.csgc.camera.biz.vip

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.viewpager.widget.ViewPager

import com.csgc.camera.bean.VipEquitiesPageData

import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.RecyclerTabLayout.Adapter
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ItemVipTabEquitiesBinding


class VipEquitiesTabAdapter(val context:Context,viewPager: ViewPager,val list:ArrayList<VipEquitiesPageData>):Adapter<VipEquitiesTabAdapter.VipEquitiesTabHolder>(viewPager) {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VipEquitiesTabHolder {
        return VipEquitiesTabHolder(ItemVipTabEquitiesBinding.inflate(LayoutInflater.from(context),parent,false))
    }

    override fun onBindViewHolder(holder: VipEquitiesTabHolder, position: Int) {
        val data = list[position]
        holder.binding.apply {
            tvEquitiesName.text = data.title
            ivEquitiesImage.setImageResource(data.image)
            if (viewPager.currentItem == position){
                root.setBackgroundResource(R.drawable.img_vip_tab_bg)

            }else{
                root.setBackgroundColor(ContextCompat.getColor(context,R.color.transparent))
            }

            root.clickWithTrigger {
                viewPager.currentItem = position
            }
        }

    }

    override fun getItemCount(): Int {
        return list.size
    }

    class VipEquitiesTabHolder(val binding:ItemVipTabEquitiesBinding):ViewHolder(binding.root)

}